package thread;

public class SyDemo2 {

    public static class Shop
    {
        public void buy()
        {
            Thread thread = Thread.currentThread();
            try {
                String name=thread.getName();
                System.out.println(name+"choosing");
                Thread.sleep(1500);
                synchronized ("hello"){
                    System.out.println(name+"trying");
                    Thread.sleep(1500);
                }
                System.out.println(name+"buying");
                Thread.sleep(1500);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
    public static void main(String[] args) {
        Shop shop1 = new Shop();
        //Shop shop2 = new Shop();
        Thread t1=new Thread("zhou"){
            public void run()
            {
                shop1.buy();
            }
        };
        Thread t2=new Thread("ming"){
            public void run()
            {
                shop1.buy();
            }
        };
        t1.start();
        t2.start();
    }
}
